package com.qi;

public class 二分查找 {

    public static void main(String[] args) {
        System.out.print(binSearch(new int[]{1}, 1));
    }


    public static int binSearch(int[] nums, int target) {
        int begin = 0;
        int end = nums.length - 1;

        while (begin <= end) {
            int mid = (begin + end) / 2;
            if (nums[mid] == target) {
                return mid;
            } else if (nums[mid] > target) {
                end = mid - 1;
            } else {
                begin = mid + 1;
            }
        }
        return -1;
    }

}
